package com.mpsc.api.bean;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class RoleInfoEntity implements Serializable {
    private long id;
    private long shardingId;
    private String roleName;
    private String roleCode;

    public static void main(String[] args) {
        int[] ms = {4, 5, 5};
        int[] as = {1, 5, 5, 10};
        int[] bs = {1, 3, 8, 8, 20};
        test(ms, as, bs);
    }

    public static void test(int[] ms, int[] as, int[] bs) {
        int m = ms[0];
        int n = ms[1];
        int r = ms[2];
        as = sort(as);
        Integer a_b = null;
        int ai = 0, bj = 0;
        List<Map<Integer, Integer>> list = new ArrayList<>();
        if (flag(1, 100000, r) && flag(1, 100000, n) && flag(1, 100000, m)) {
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    if (as[i] <= bs[j]) {
                        if (a_b == null)
                            a_b = bs[j] - as[i];
                        int ab = bs[j] - as[i];
                        if (a_b >= ab) {
                            ai = as[i];
                            bj = bs[j];
                            a_b = ab;
                        }
                        if (j == n - 1 && ai != 0 && bj != 0 && a_b <= r) {
                            a_b = null;
                            list.add((Map<Integer, Integer>) new HashMap<>().put(ai, bj));
                        }
                    }
                }
            }
        }
        for (int len = list.size(), i = 0; i < len; i++) {
            list.get(i).forEach((k, v) -> System.out.println(k + " " + v));
        }
    }

    private static int[] sort(int[] as) {
        int temp;
        for (int leni = as.length, i = 0; i < leni; i++) {
            for (int lenj = as.length, j = i; j < lenj; j++) {
                if (as[i] > as[j]) {
                    temp = as[i];
                    as[i] = as[j];
                    as[j] = temp;
                }
            }
        }
        return as;
    }

    private static boolean flag(int min, int max, int num) {
        if (num >= min && num <= max) {
            return true;
        }
        return false;
    }

}
